import { request } from "@/utils/request";
import type {
  DeleteParams,
  TableParams,
  QueryParams,
  QueryResult,
  QueryFieldParams,
  QueryFieldResult,
  PublishParams,
} from "./typing";
import type { PageResult, ResponseBody } from "@/api/typing";

/**分页查询数据表 */
export const queryByPage = (params: QueryParams) => {
  return request.get<QueryParams, ResponseBody<PageResult<QueryResult>>>(
    "/low-code/table/page",
    { params }
  );
};

/**新增数据表 */
export const add = (params: TableParams) => {
  return request.post<TableParams, ResponseBody>("/low-code/table/add", params);
};

/**修改数据表 */
export const update = (params: TableParams) => {
  return request.put<TableParams, ResponseBody>(
    "/low-code/table/update",
    params
  );
};

/**删除数据表 */
export const del = (params: DeleteParams) => {
  return request.delete<DeleteParams, ResponseBody>("/low-code/table/delete", {
    params,
  });
};

/**查询数据表字段 */
export const queryFields = (params: QueryFieldParams) => {
  return request.get<QueryFieldParams, ResponseBody<QueryFieldResult[]>>(
    "/low-code/table/field/list",
    { params }
  );
};

/**发布数据表 */
export const publish = (params: PublishParams) => {
  return request.post<PublishParams, ResponseBody>(
    "/low-code/table/publish",
    params
  );
};
